Page({
  data: {
    tipTitle: '提醒',
    tipContent: '登出后无法享受会员优惠和专属服务，是否继续？'
  },
  onLoad: function (options) {
    this.setData({
      nickname: options.nickname,
      avatar: options.avatar
    });
    wx.util.request('message.config').then(config => {
      this.setData({
        isOpen: config.all == 1
      });
    });
  },
  href: function (e) {
    let page = e.currentTarget.dataset.page, url = '';
    if (page == 'notify') {
      this.setData({
        showSwitch: true
      });
    } else {
      switch (page) {
        case 'info':
          url = 'info';
          break;
        case 'address':
          url = '../address/index';
          break;
        case 'feedback':
          url = '../feedback/new';
          break;
        case 'us':
          url = '../help/aboutUs';
          break;
        default:
          break;
      }
      if (!url) {
        wx.util.toast('即将开放');
        return;
      }
      wx.navigateTo({
        url: url
      });
    }
  },
  modify: function (e) {
    let act = e.detail.value;
    wx.util.request('message.modify', {
      body: {all: (act ? 1 : 0)}
    }).then(() => {
      this.setData({
        isOpen: act
      });
      this.hide();
    });
  },
  logout: function () {
    this.setData({
      showModal: true
    });
  },
  modal: function (e) {
    this.hide();
    if (e.detail.key == 'confirm') {
      wx.user.logout();
      wx.navigateBack();
    }
  },
  hide: function () {
    this.setData({
      showSwitch: false,
      showModal: false
    });
  }
})